"""
Case Type   : datakit安装
Case Name   : 安装非法插件
Create At   : 2025/4/21
Owner       : @lonely-dance
Description :
    1.安装非法插件
Expect      :
    1.合理报错
History     :
"""

import os
import unittest

from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH
from testcase.utils.datakit_api.CommonApi import CommonApi


class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f"-----{os.path.basename(__file__)} start-----")
        self.com_sh = CommonSH()
        self.datakit_node = Node('Datakit_Root')
        self.token = self.com_sh.get_token_value(macro.DATAKIT_PASSWD)
        self.log.info(self.token)
        self.assertNotEqual("error", self.token)
        self.com_api = CommonApi(self.token)

    def test_base_ops(self):
        text = '----step1:安装非法插件 expect:合理报错----'
        self.log.info(text)
        cmd = f'''ls {macro.DATAKIT_INSTALL_PATH}|grep jar'''
        res = self.datakit_node.sh(cmd).result()
        self.log.info(res)
        jar_path = os.path.join(f"{macro.DATAKIT_INSTALL_PATH}", res)
        response = self.com_api.post_system_plugins_offline_install(jar_file=jar_path)
        self.log.info(response.json())
        self.assertIn("plugin install error", response.json()['msg'])

    def tearDown(self):
        self.log.info('----无需清理环境----')
        self.log.info(f"-----{os.path.basename(__file__)} finsh-----")
